package com.cinsea.ext.xyc;

import com.cinsea.common.ActionType;
import com.cinsea.common.BasePX;
import com.cinsea.common.Env;
import com.cinsea.common.JdbcDao;
import com.cinsea.htmlselect.service.OptionService;
import com.cinsea.interfaces.form.Formdata;
import com.cinsea.interfaces.form.FormdataServiceImpl;
import com.cinsea.interfaces.model.Cell;
import com.cinsea.interfaces.model.Dataset;
import com.cinsea.interfaces.workflow.RequestInfo;
import com.cinsea.security.service.RightService;
import com.cinsea.util.DateUtil;
import com.cinsea.util.StringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-31
 * Time: 上午10:30
 * To change this template use File | Settings | File Templates.
 */
public class HandselPx extends BasePX {
    @Override
    public void before(Map context) {
        JdbcDao jdbcDao = Env.getBean("jdbcDao");
        String actiontype = StringUtil.null2String(context.get("actiontype"));
        Map m=(Map)context.get("parameters");
        String lzid = StringUtil.null2String(m.get("ut_handselplant_lvzhi"));
        String hhsl = StringUtil.null2String(m.get("ut_handselplant_amount"),"0");
        if(actiontype.equals(ActionType.SUBMIT_WFPROCESS)){
            String apper = StringUtil.null2String(m.get("ut_handselplant_shenqingren"),Env.getRemoteUser().getId());
            String appdate = StringUtil.null2String(m.get("ut_handseleplant_shenqingriqi"),DateUtil.getCurrentDate());
            String apptime = StringUtil.null2String(m.get("ut_handselplant_sqsj"),DateUtil.getCurrentTime());
            FormdataServiceImpl si = new FormdataServiceImpl();
            Formdata formdata = new RequestInfo();
            formdata.setOperator(Env.getRemoteUser().getId());
            formdata.setTypeid("402881934060ce6c01406194917b000d"); //换花申请目录id
            Dataset ds = new Dataset();
            List<Cell> mainlist = new ArrayList(); //主表单元格
            Cell c2 = new Cell();
            c2.setId("ut_changeplant_lvzhi");
            c2.setValue(lzid);
            Cell c4 = new Cell();
            c4.setId("ut_changeplant_applier");
            c4.setValue(apper);
            Cell c5 = new Cell();
            c5.setId("ut_changeplant_appdate");
            c5.setValue(appdate);
            Cell c6 = new Cell();
            c6.setId("ut_changeplant_apptime");
            c6.setValue(apptime);
            String type ="402881ee4278282501427985399104c4";//赠花
            Cell c7 = new Cell();
            c7.setId("ut_changeplant_hhlx");
            c7.setValue(type);
            Cell c8 = new Cell();
            c8.setId("ut_changeplant_hhzt");
			c8.setValue("402881934061fddd0140622fbc2a0009");//已申请换花
            Cell c9 = new Cell();
            c9.setId("ut_changeplant_xgkh");
            c9.setValue(StringUtil.null2String(m.get("ut_handselplant_xgkh")));
           /* Cell c10 = new Cell();
            c10.setId("ut_changeplant_cgry");
            String cgry = StringUtil.null2String(m.get("ut_handselplant_cgry"));
            if(!(cgry.equals(""))){
                c10.setValue(cgry);
                c8.setValue("402881934061fddd0140622fe59a000a");//已分配采购
            }
            else{*/
               
           // }
            Cell c11 = new Cell();
            c11.setId("ut_changeplant_hhbz");
            c11.setValue(StringUtil.null2String(m.get("ut_handselplant_beizhu")));
            OptionService optionService = Env.getBean("optionService");
            Map lvzhidata = jdbcDao.queryForMap("select guigexinghao,chmc,chdlmc from ut_plantinfo where processid=?", new Object[]{lzid});
            Cell c12 = new Cell();
            c12.setId("ut_changeplant_guigexinghao");
            c12.setValue(StringUtil.null2String(optionService.get(StringUtil.null2String(lvzhidata.get("guigexinghao"))).getObjname()));
            Cell c13 = new Cell();
            c13.setId("ut_changeplant_lzmc");
            c13.setValue(StringUtil.null2String(lvzhidata.get("chmc")));
            Cell c14 = new Cell();
            c14.setId("ut_changeplant_lzlx");
            c14.setValue(StringUtil.null2String(optionService.get(StringUtil.null2String(lvzhidata.get("chdlmc"))).getObjname()));
            Cell c15 = new Cell();
            c15.setId("ut_changeplant_jieshouren");
            c15.setValue(StringUtil.null2String(m.get("ut_handselplant_jieshouren")));
            Cell c16 = new Cell();
            c16.setId("ut_changeplant_hhsl");
            c16.setValue(hhsl);
            mainlist.add(c2);
            mainlist.add(c4);
            mainlist.add(c5);
            mainlist.add(c6);
            mainlist.add(c7);
            mainlist.add(c8);
            mainlist.add(c9);
           // mainlist.add(c10);
            mainlist.add(c11);
            mainlist.add(c12);
            mainlist.add(c13);
            mainlist.add(c14);
            mainlist.add(c15);
            mainlist.add(c16);
            ds.setMaintable(mainlist);
            formdata.setData(ds);
            si.createFormdata(formdata);

           // String sq = "select processid from ut_changeplant where ";
           // RightService rightService=Env.getBean("rightService");
           // rightService.reCreateRightdetail(, "0", "ut_changeplant");
        }
    }
}
